<template>
  <div id="Common">
    <v-detail
      :detailData="inputData"
      :inputConfig="inputConfig"
      :rules="rules"
      ref="input"
      @pop="setData"
    ></v-detail>
  </div>
</template>

<script>
import detail from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "Common",
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object,
    },
  },
  data() {
    return {
      addflag: false,
      whseidflag: false,
      rules: {
        storerkey: [{ required: true, trigger: "blur" }],
        parent: [{ validator: this.parent, trigger: "blur" }],
      },
    };
  },
  computed: {
    inputConfig() {
      return [
        [
          {
            type: "input",
            label: this.$t("config.deliveryAddress"),
            props: "storerkey",
            disabled: this.addflag,
          },
          {
            type: "input",
            label: this.$t("config.company"),
            props: "company",
            disabled: this.whseidflag,
          },
        ],
        [
          {
            type: "input",
            label: this.$t("common.desc"),
            props: "description",
            disabled: this.whseidflag,
          },
          {
            type: "input",
            label: this.$t("config.scacCode"),
            props: "scac_Code",
            disabled: this.whseidflag,
          },
        ],
        [
          {
            type: "input",
            label: this.$t("config.addIdentifier"),
            props: "vat",
            disabled: this.whseidflag,
          },
          {
            type: "input",
            label: this.$t("config.accountingentity"),
            props: "accountingentity",
            disabled: this.whseidflag,
          },
        ],
        [
          {
            type: "table",
            label: this.$t("config.parentItem"),
            props: "parent",
            disabled: this.whseidflag,
            tableConfig: [
              {
                label: this.$t("config.shipper"),
                prop: "storerkey",
                input: "input",
              },
              {
                label: this.$t("common.type"),
                prop: "type",
                input: "select",
                options: this.getOptions(`querycodeLkup/STORERTYPE`),
              },
              {
                label: this.$t("config.company"),
                prop: "company",
                input: "input",
              },
            ],
            url: `/queryStorer3/?/${this.$store.state.wms}`,
          },
          {
            type: "checkbox",
            label: this.$t("config.trayExchangeFollow"),
            props: "containerexchangeflag",
            disabled: this.whseidflag,
          },
        ],
      ];
    },
  },
  methods: {
    parent(rule, value, callback) {
      if (value === "") {
        callback();
      } else {
        this.$api
          .post(`/queryStorer4/${this.$store.state.wms}/${value}`, {})
          .then((res) => {
            
              callback();
          }).catch(e => {
            this.$message.error(e.returnMgr);
            this.inputData[rule.field] = "";
            callback(new Error());
          })
      }
    },
    setData(data, id, close, listId) {
      this.inputData.parent = data.storerkey;
      close(false);
    },
  },
  mounted() {
    if (this.$store.state.wms.toUpperCase().includes("WMWHSE")) {
      //仓库级
      this.addflag = this.whseidflag = true;
    }
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      if (data.newFlag) {
        this.addflag = false;
      } else {
        this.addflag = true;
      }
    } else if (this.$store.state.newFlag) {
      this.addflag = false;
    } else {
      this.addflag = true;
    }
  },
  components: {
    "v-detail": detail,
  },
};
</script>

<style scoped></style>
